/*
 * Copyright (c) 2023. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.gzdh.device.system.model;

 import com.gzdh.device.system.entity.SysPermission;
 import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class MenuTreeModel implements Serializable {


    private static final long serialVersionUID = 1L;

    private String parentId;

    private String id;

    private String path;

    private String name;

    private String component;

    private String icon;

    private boolean isLeaf;

    private MenuMetaModel meta;

    private List<MenuTreeModel> children = new ArrayList<>();

    public MenuTreeModel(SysPermission sysPermission) {
        this.id = sysPermission.getId();
        this.parentId = sysPermission.getParentId();
        this.name = sysPermission.getName();
        this.icon = sysPermission.getIcon();
        this.component = sysPermission.getComponent();
        this.path = sysPermission.getUrl();

        MenuMetaModel menuMetaModel = new MenuMetaModel();
        menuMetaModel.setTitle(sysPermission.getName());
        menuMetaModel.setIcon(sysPermission.getIcon());
        menuMetaModel.setHideMenu(sysPermission.getHidden() != 0);
        menuMetaModel.setShowMenu(sysPermission.getShowMenu() != 0);
        this.meta = menuMetaModel;
    }

    public void setChildren(List<MenuTreeModel> children) {
        if (children == null) {
            this.isLeaf = true;
        }
        this.children = children;
    }

}
